<template>
	<view class="add">
		<block v-if="!boxHide">
			<view class="add_item">
				<view >{{text}}结果</view>
 				<view class="add_sex">
					<text :class="upJson.status == 1 ? 'active' : ''" @tap="setSex(1,'status')">通过</text>
					<text :class="upJson.status == 2 ? 'active' : ''" @tap="setSex(2,'status')">拒绝</text>
				</view>
			</view>
			
			<view class="add_item" v-if="type == 2">
				<view>是否入库</view>
				<view class="add_sex">
					<text :class="upJson.into == 1 ? 'active' : ''" @tap="setSex(1,'into')">需入库</text>
					<text :class="upJson.into == 2 ? 'active' : ''" @tap="setSex(2,'into')">不入库</text>
				</view>
			</view>
			
			<view class="add_textarea" v-if="!boxHide">
 				<view  >{{text}}意见</view>
 				<textarea :placeholder="'请输入'+text+'意见'" v-model="upJson.desc"/>
 
			</view>
			
			<view class="save" @tap="save()">{{text}}</view>
 
		</block>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				type:1,   // 1表示审批     2表示审核
				title:['完成拜访','修改拜访','留言','','','添加拜访'],
				visitLaber:[],
				upJson:{
					into:1,
					status:1,
					id:"",
					order_id:"",
					desc:""
				},
				visitId:"",
				boxHide:false,
				text:'审批'
			}
		},
		onLoad(options) {
			this.upJson.order_id = Number(options.order_id);
			this.upJson.id = Number(options.id);
			this.type = options.type;
			if(this.type==2){
				this.text = '审核';
			}else{
				this.text = '审批';
			}
		},
		onShow() {
			
		},
		methods:{
			setSex(index,obj){
				this.upJson[obj] = index
			},
			save(){
				if(this.type == 2){

					if(this.upJson.desc.length == 0){
						this.$api.prompt("审核内容不能为空");
					}else{
						this.$api.auditReturn(this.upJson).then(res =>{
							this.$app.globalData.upData.return = true
						})
					}
				}else{

					this.approve();

				}
			},
			approve(){ // 审核

				let params = {id:this.upJson.id,status:this.status,order_id:this.upJson.order_id,desc:this.upJson.desc};

				params.user_id = uni.getStorageSync("userId");

				if(this.upJson.desc.length == 0){
					this.$api.prompt("审批内容不能为空");	
				}else{
					this.$api.approveReturn(this.upJson).then(res =>{
						this.$app.globalData.upData.return = true
					})
				}
				

			}
		}
	}
</script>

<style>
	.add{background: #FFFFFF;}
	.add_sex text{width: 120upx;}
</style>